package com.fmsz.physicalheadline.activitys.event;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.test.mock.MockApplication;
import android.util.Log;
import android.widget.Toast;

import com.fmsz.physicalheadline.BR;
import com.fmsz.physicalheadline.R;
import com.fmsz.physicalheadline.application.MyApplication;
import com.fmsz.physicalheadline.databinding.ActivityMatchContentBinding;
import com.fmsz.physicalheadline.entity.events.MatchContent;
import com.fmsz.physicalheadline.entity.events.MatchData;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MatchContentActivity extends AppCompatActivity implements Callback<MatchContent> {

    private long contest_id;
    private int contest_type;
    private String cup_name;
    private ActivityMatchContentBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_match_content);
        Intent intent = getIntent();
        contest_id = intent.getLongExtra("contest_id",-1);
        contest_type = intent.getIntExtra("contest_type",0);
        cup_name = intent.getStringExtra("cup_name");
        binding.setMatchTitle(cup_name);
        ((MyApplication) getApplication()).getHttpService().getSecMatch(contest_id,contest_type).enqueue(this);
    }

    @Override
    public void onResponse(Call<MatchContent> call, Response<MatchContent> response) {
        MatchContent body = response.body();
        if (body.getCode()==200) {
//            MatchData data = body.getData();
            binding.setVariable(BR.matchContent,body);
        }
    }

    @Override
    public void onFailure(Call<MatchContent> call, Throwable t) {
        t.printStackTrace();
        Log.i("1620", "onFailure: "+t.getMessage());
        Toast.makeText(this, t.getMessage(), Toast.LENGTH_SHORT).show();
    }
}
